package com.cqhfan.imservice.mq;

import com.cqhfan.core.constans.MqConstants;
import com.cqhfan.imservice.service.SystemMessageService;
import com.cqhfan.pojo.im.dto.SystemMessageDTO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author 眭传洪
 * @create 2025-08-18 0:07
 */
@Slf4j
@Component
public class SystemMessageListener {

    @Resource
    private SystemMessageService systemMessageService;

    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange(value = MqConstants.EXCHANGE.SYSTEM_MESSAGE_SEND_EXCHANGE, type = ExchangeTypes.FANOUT),
            value = @Queue(value = MqConstants.QUEUE.SYSTEM_MESSAGE_SEND_QUEUE)
    ))
    public void listenSystemMessageSend(SystemMessageDTO message) {
        log.info("mq接收系统消息发送, msg = {}", message);
        systemMessageService.listenSystemMessageSend(message);
    }

}
